package com.example.shopping2.a_c_fragment.home.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.viewpager.widget.PagerAdapter
import com.bumptech.glide.Glide
import com.example.shopping2.R
import com.example.shopping2.a_c_fragment.home.entity.Vip_Entity

class Vip_Adapter(private var list: ArrayList<Vip_Entity>) : PagerAdapter() {

    override fun getCount(): Int {
        return list.size
    }

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view == `object`
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        var inflate = LayoutInflater.from(container.context).inflate(R.layout.home_vip, null)
        var vipimg = inflate.findViewById<ImageView>(R.id.home_vip)
        var lp = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        inflate.layoutParams = lp
        container.addView(inflate)
        Glide.with(container.context).load(list.get(position).url).into(vipimg)
        return inflate
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        super.destroyItem(container, position, `object`)
        val view = `object` as View
        container.removeView(view)

    }
}